<?php
namespace Plu\Library\Models\Platform\Media;

use Phalcon\Mvc\Model,
	Phalcon\Db\Column;

class MediaLiveApp extends Model {
    public $Id;

    public $MediaId;//视频id

    public $OnlineCount;//最终在线人数

    public $WatchCount;//总在线人数

    public $ItemCount;//点赞数

    public $Longitude;//经度

    public $Latitude;//纬度

    public $Address;//地址

    public function initialize() {
        $this->setReadConnectionService('db.LongzhuMediaReadOnly');
    }

    public function getSource() {
        return "MediaLiveApp";
    }

    /**
     * 获取视频额外信息
     */
    static public function getItems($ids) {
        if (!is_array($ids)) {
            $ids = array($ids);
        }

        $sql = array();
        $len = count($ids);
        $bind = array();
        $bindTypes = array();

        for ($c = 0; $c < $len; $c++) {
            $p = "v{$c}";
            $sql[] = " MediaId = :{$p}: ";
            $bind[$p] = $ids[$c];
            $bindTypes[$p] = Column::BIND_PARAM_INT;
        }

        $sql = join(" OR ", $sql);

        $videos = self::find(array(
            $sql,
            'bind' => $bind,
            'bindTypes' => $bindTypes
        ));
        $videos = $videos->toArray();

        $items = array_combine(array_column($videos, 'MediaId'), $videos);
        return $items;
    }
}
?>
